import { _decorator, Component, Label, Node, v3, Widget } from 'cc';
import { gameMgr } from '../gameMgr';
import { Tools } from './Tools';
const { ccclass, property } = _decorator;

@ccclass('gameRevival')
export class gameRevival extends Component {

    //复活进度的文字
    @property(Label)
    revive_progress_lab: Label = null;
    
    //复活中
    reviveing = false;

    revive_num = 1

    start() {

    }

    on_open(){
        if(this.reviveing)return;
        this.reviveing = true;

        this.revive_num--;
        if(this.revive_num < 0){
            console.log("复活次数不足")
            this.on_game_over()
            return;
        }

        Tools.updateWidget(this.node);

        this.revive_progress_lab.string = "目前已完成"+gameMgr.Inst.cur_progress+"%的进度" 

    }

    on_close(){
        this.node.getComponent(Widget).enabled = false;
        this.node.setPosition(v3(1024 , 0 , 0 ));
        this.reviveing = false;
    }

    on_game_over(){
        this.on_close();
        gameMgr.Inst.on_game_over();
    }

    /** 复活 */
    onGetRevive(){
        console.log("复活")

        gameMgr.Inst.onRevive();
        this.on_close();
    }
}


